#pragma once
#include <memory>
#include <mutex>
#include <map>
#include <condition_variable>
#include "Pal/AudioEnc.h"
#include "AVFrame.h"
#include "frame_common.h"
namespace Media{

    typedef struct{


    }AEncoderConfig;

    class AEncoder{
    public:
        using Ptr = std::shared_ptr<AEncoder>;
        using FrameConsumerId = uint32_t;

        AEncoder(int channel, const AEncoderConfig& config);
        ~AEncoder();

        bool Start();
        bool Stop();

        // bool InputAVFrame(AVFrame::Ptr frame);
        bool InputAVFrame(void* frame);

        FrameConsumerId AddConsumer(std::function<void (const FrameCommon::Frame::Ptr&)> consumer);
        bool RemoveConsumer(FrameConsumerId id);

        int GetChannel();
    private:
        bool init();
        void packetProc();
        std::map<FrameConsumerId, std::function<void (const FrameCommon::Frame::Ptr&)>> m_frameConsumers;
        uint32_t m_frameConsumerIndex;
        std::recursive_mutex m_mux;

        std::mutex m_cvMux;
        std::condition_variable m_cv;

        AudioEncoder *m_encoder;
        AEncoderConfig m_config;
        int m_channel;
        bool m_running;
    };
}